<template>
	<view class="page">
		<cu-custom  bgColor="bg-white" :isBack="true"><block slot="content">活动专区</block></cu-custom>
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" height="93%" top="0" :down="downOption" @down="downCallback" :up="upOption" @up="upCallback" @emptyclick="emptyClick">
			<view class="cu-card case">
				<view class="cu-item margin-left-sm" v-for="(item,index) in tourList" :key="index"  @tap="goToDetail(item.active_id)">
					<view class="image">
						<image :src="item.active_face" mode="widthFix" style="max-height: 300rpx;"></image>
					</view>
					<view class="cu-list padding-sm" style="padding-top: 10rpx;">
						<view class="cu-item">
							<view class="content flex justify-between align-center">
								<view>
									<view class="text-333 text-df text-fw600">{{item.active_title}}</view>
									<view class="flex align-end flex-wrap" style="margin-top: 10rpx;">
										<text class="text-theme text-df margin-right-sm text-fw600" v-if="item.active_price">￥{{item.active_price | formatPrice}}/张</text>
										<text class="text-666 text-sm" style="margin-right:10rpx;padding-bottom: 2rpx;" v-if="item.limit_buy_num>0">限购{{item.limit_buy_num}}张/人</text>
										<text class="text-666 text-sm" style="padding-bottom: 2rpx;">剩余{{item.enable_quantity}}张 </text>
									</view>
								</view>
								<view class="flex" @tap.prevent.stop="buy(item,item.active_id)">
									<text class="buy-btn text-df" :class="item.operation=='NO'?'bg-theme':'bg-999'">{{item.operation_text}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-uni>
		<view class="cu-bar padding bg-white" style="position: fixed; bottom:0; width: 100%;" @tap="handleRecord">
			<view class="content text-theme text-df text-fw500">购买记录</view>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
	import * as Tour_API from '@/api/tour.js' 
	import {share} from '@/utils/Foundation.js'
	export default {
		mixins: [MescrollMixin,MescrollMoreItemMixin], 
		data() {
			return {
				price:2599,
				params:{
					page_no:1,
					page_size:20,
					// 专区（SPECIAL:特价 FREE:免费 PROFIT:权益）
					// status:'FREE'
				},
				downOption:{
					auto:false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption:{
					auto:false,
					noMoreSize: 8, //列表的总数量要大于半页才显示无更多数据;默认5
					empty:{
						icon:'/static/images/empty/empty_order.png',
						tip: '暂未查询到活动'
					}
				},
				tourList:[]
			};
		},
		onShow() {
			// this.GET_TourList()
		},
		
		methods:{
			// onShareAppMessage() {
			// 	let path='pages/activity/tour/zone'
			// 	share(path,'activity',title)
			// 	return{
			// 		title:title
			// 	}
			// },
			onShareAppMessage() {
				let title = '热门活动，等你加入'
				let page_path = 'pages/activity/tour/zone'
				let mobile = uni.getStorageSync('userInfo').mobile
				let user = uni.getStorageSync('userInfo').nickname
				let shop_name = uni.getStorageSync('shop').shop_name
				let shop_id = uni.getStorageSync('shop').shop_id
				let path = ''
				if(mobile && shop_id){
					path = page_path+'?shop_id='+shop_id+'&sharePhone='+mobile
				}else if(shop_id){
					path =  page_path+'?shop_id='+shop_id
				}
			    return {
					title: title,
					path: path
			    }
			},
			downCallback() {
				// this.params.keyword = ''
				this.params.page_no =1
				this.mescroll.resetUpScroll()
			},
			upCallback(page) {
				Tour_API.getTourList(this.params).then(res =>{
					this.mescroll.endSuccess(res.data.length)
					if(this.params.page_no ==1) this.tourList = []
					this.tourList = this.tourList.concat(res.data)
					this.params.page_no+=1
				}).catch(()=>{
					this.mescroll.endErr();
				})
			},
			//点击空布局按钮的回调
			emptyClick(){
				
			},
			GET_TourList(){
				Tour_API.getTourList(this.params).then(res =>{
					console.log(res)
					this.tourList = res.data
				})
			},
			buy(item,active_id){
				if(item.operation=='NO'){
					if(!uni.getStorageSync('token')){
						uni.navigateTo({url:'/pages/login/login'})
					}else{
						uni.navigateTo({
							url:'./orderConfirm?active_id='+active_id
						})
					}
				}
			},	
			goToDetail(active_id){
				// console.log('zoom', active_id)
				if(active_id){
					uni.navigateTo({
						url:'./activityDetail?active_id='+active_id
					})
				}
			},
			handleRecord(){
				if(!uni.getStorageSync('token')){
					uni.navigateTo({url:'/pages/login/login'})
				}else{
					uni.navigateTo({url:'./orderList'})
				}
				
			}
		}
	}
</script>

<style lang="scss">
.text-666{
	color: #666;
}	
/deep/.cu-card>.cu-item {
	margin: 30rpx 20rpx;
}
.buy-btn{
	padding: 10rpx 20rpx 10rpx 28rpx;
	border-radius: 10rpx;
	overflow: hidden;
	font-size: 26rpx;
	letter-spacing:8rpx;
}
.bg-999{
	background: #E1E1E1;
	color:#FFF;
}
</style>
